package com.qf.votedemo.handler;

import cn.hutool.extra.mail.MailUtil;
import com.qf.votedemo.vo.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author 刘欣
 * @createTime 2023/2/24 17:23
 * @description 全局异常处理器
 */
@RestControllerAdvice
@Slf4j
public class Exhandler {

    @ExceptionHandler(Exception.class)
    public ResultVo exception(Exception e) {
        log.debug("系统异常exception={}", e.getMessage());
        MailUtil.send("875645208@qq.com", "线上bug", e.getMessage(), false);
        return ResultVo.error(e.getMessage());
    }
}
